<!DOCTYPE html>
<html>
<body>
<script src="../resources/runner.js"></script>

<textarea id="testElement" spellcheck=false style="height:90vh"></textarea>

<script>
var isDone = false;
var startTime;

function runTest() {
    if (startTime) {
        PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime);
        PerfTestRunner.addRunTestEndMarker();
    }
    if (!isDone) {
        PerfTestRunner.addRunTestStartMarker();
        startTime = PerfTestRunner.now();

        // Fill the textarea with 1000 lines of random numbers.
        var testElement = document.getElementById('testElement');
        testElement.textContent = new Array(333).fill(0).map(
            (_, i) => Math.floor(100*Math.random())).join('\n');

        // Wait to allow the asynchronous accessibility code that's
        // covered by traceEventsToMeasure to have a chance to run.
        setTimeout(runTest, 2500);
    }
}

PerfTestRunner.startMeasureValuesAsync({
    description: 'Test accessibility performance when appending to a textarea.',
    unit: 'ms',
    done: function () {
        isDone = true;
    },
    run: function() {
        runTest();
    },
    iterationCount: 6,
    tracingCategories: 'accessibility',
    traceEventsToMeasure: [
        'BrowserAccessibilityManager::OnAccessibilityEvents',
        'ProcessDeferredAccessibilityEvents',
        'RenderAccessibilityImpl::SendPendingAccessibilityEvents',
    ]
});
</script>

</html>
